<template>
    <div>
<h2>登录</h2>
<table class="table">
<tbody>
    <tr>
        <td>账号</td>
        <td> 
            <input type="text" v-model="model.UserName">
        </td>
    </tr>


    <tr>
        <td>密码</td>
        <td>
            <input type="password" v-model="model.UserPwd">
        </td>
    </tr>




    <tr>
        <td></td>
        <td>
            <input type="button" value="登录" class="btn btn-success" @click="ok">
        </td>
    </tr>
</tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';
const route=useRoute();
const router=useRouter();

//定义变量
let model=reactive({
  "UserName": '',
  "UserPwd": '',
})


//登录
const ok=()=>{

if(model.UserName==""){
    alert('账号不能为空');
    return;
}


if(model.UserPwd==""){
    alert('密码不能为空');
    return;
}


axios({
url:'https://localhost:7276/api/admin/Login',
method:'post',
data:model,
})

.then((res)=>{
    console.log(res);
    if(res.data==0){
        alert('账号不存在');
        return;
    }
    else if(res.data==-1){
        alert('密码错误');
        return;
    }
    else{
        alert('登录成功');
        router.push('/UserList')
        return;

    }
})


.catch((ree)=>{
    console.log(ree);      
})



}

</script>

<style scoped>

</style>